package com.yunchang.springboot.scheduled.amazon.mws.report.datadispose;

import com.yunchang.springboot.models.Shop;
import com.yunchang.springboot.models.mwsreportbean.MwsReservedInventory;
import com.yunchang.springboot.models.mwsreportbean.MwsReservedInventoryDO;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.parent.ReportDataDisposeParent;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.reportinterface.IReportDataDispose;
import com.yunchang.springboot.utils.DateUtil;
import com.yunchang.springboot.utils.ToolUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author czw
 * @date 2020/7/28 0028  18:51
 * @description:
 */
@Component
public class ReservedInventoryDataDispose extends ReportDataDisposeParent implements IReportDataDispose {

    /**
     * 预留库存  将获取到的数据转为实体对象数组
     *
     * @param lists
     * @param shopBrandName
     * @param area
     * @return
     */
    @Override
    public List<Object> reportDataDispose(List<List<String>> lists, String shopBrandName, String area,String sellerId) {
        List<String> titleList = lists.get(0);
        Map<String, Object> titleMap = new HashMap<>(titleList.size());
        for (int i = 0; i < titleList.size(); i++) {
            titleMap.put(titleList.get(i), i);
        }
        int skuIndex = Integer.valueOf(titleMap.get("sku").toString());
        int fnskuIndex = Integer.parseInt(titleMap.get("fnsku").toString());
        int asinIndex = Integer.valueOf(titleMap.get("asin").toString());
        int productNameIndex = Integer.valueOf(titleMap.get("product-name").toString());
        int reservedQtyIndex = Integer.valueOf(titleMap.get("reserved_qty").toString());
        int reservedCustomerordersIndex = Integer.valueOf(titleMap.get("reserved_customerorders").toString());
        int reservedFcTransfersIndex = Integer.valueOf(titleMap.get("reserved_fc-transfers").toString());
        int reservedFcProcessingIndex = Integer.valueOf(titleMap.get("reserved_fc-processing").toString());
        List<Object> insertList = new ArrayList<>(lists.size());
        for (int i = 1; i < lists.size(); i++) {
            MwsReservedInventoryDO mwsReservedInventory = new MwsReservedInventoryDO();
            List<String> stringList = lists.get(i);
            mwsReservedInventory.setShop(shopBrandName);
            mwsReservedInventory.setArea(area);
            mwsReservedInventory.setSku(stringList.get(skuIndex));
            mwsReservedInventory.setFnsku(stringList.get(fnskuIndex));
            mwsReservedInventory.setAsin(stringList.get(asinIndex));
            mwsReservedInventory.setProductName(stringList.get(productNameIndex));
            mwsReservedInventory.setReservedQty(ToolUtil.valueOfInteger(stringList.get(reservedQtyIndex)));
            mwsReservedInventory.setReservedCustomerorders(ToolUtil.valueOfInteger(stringList.get(reservedCustomerordersIndex)));
            mwsReservedInventory.setReservedFcTransfers(ToolUtil.valueOfInteger(stringList.get(reservedFcTransfersIndex)));
            mwsReservedInventory.setReservedFcProcessing(ToolUtil.valueOfInteger(stringList.get(reservedFcProcessingIndex)));
            mwsReservedInventory.setCreateTime(DateUtil.getTodayDate("yyyy-MM-dd HH:mm:ss"));
            mwsReservedInventory.setUpdateTime(DateUtil.getTodayDate("yyyy-MM-dd HH:mm:ss"));
            mwsReservedInventory.setSellerId(sellerId);
            mwsReservedInventory.setFinanceStatus(1);
            insertList.add(mwsReservedInventory);
        }
        return insertList;
    }
}
